/*eslint-disable*/

/**特殊保留字符检测*/
function SpecialReservedCharacterDetect(StringData, NeedDetectChar) {

    let DisableSymbol;//字符库存储变量
    let FinalDetectValue = false;//最终检测值，True Or False

    //根据运行环境类别载入字符库
    switch (process.platform) {
        case "linux":
            DisableSymbol = [':', '/', '\\', '?', '*', '\"', '<', '>', '|', '\''];
            break;
        case "win32":
            DisableSymbol = [':', '/', '\\', '?', '*', '\"', '<', '>', '|'];
            break;
    }

    if (Object.prototype.toString.call(NeedDetectChar) === "[object String]") {
        if (StringData.indexOf(NeedDetectChar) >= 0) {
            FinalDetectValue = true;
        }
    } else {
        for (let SRcd in DisableSymbol) {
            if (StringData.indexOf(DisableSymbol[SRcd]) >= 0) {
                FinalDetectValue = true;
                break;
            }
        }
    }
    return FinalDetectValue;
}

/**获取全路径的文件、目录名称*/
function getFullPathFileOrDirectoryName(FullPathData) {
    let detectString;
    let FinalGetDate;
    if (Object.prototype.toString.call(FullPathData) === "[object String]") {
        switch (process.platform) {
            case "linux":
                detectString = "/";
                break;
            case "win32":
                detectString = "\\";
                break;
        }
        if (SpecialReservedCharacterDetect(FullPathData, detectString)) {
            for (let pointCount = FullPathData.length; pointCount >= 0; pointCount--) {
                if (FullPathData.charAt(pointCount) === detectString) {
                    FinalGetDate = FullPathData.substr(pointCount + 1);
                    break;
                }
            }
        } else {
            throw new Error("貌似路径格式不合法！");
        }
    } else {
        throw new Error("全路径数据必须是字符串！");
    }
    return FinalGetDate;
}

/**获取文件名的拓展名（后缀名）*/
function getFileNameExtName(FullFileName) {
    let finalExtName;
    if (Object.prototype.toString.call(FullFileName) === "[object String]" && FullFileName.length > 0) {
        if (FullFileName.indexOf(".") >= 0 && FullFileName.length > 1) {
            let dio;
            for (let deCount = (FullFileName.length); ; deCount--) {
                if (FullFileName.charAt(deCount) === ".") {
                    dio = deCount;
                    break;
                }
            }
            finalExtName = FullFileName.substr(dio);
        } else {
            finalExtName = '';
        }
    } else {
        finalExtName = '';
    }
    return finalExtName;
}

/**获取文件所在目录位置*/
function getFileOnDirectoryLocation(FullFilePath) {
    let finalFileOnPath;
    if (Object.prototype.toString.call(FullFilePath) === "[object String]") {
        if (FullFilePath.indexOf("\\") >= 0 || FullFilePath.indexOf("/") >= 0) {
            let currentRightOneSTSymbolLocation;
            currentRightOneSTSymbolLocation = FullFilePath.length;
            for (; currentRightOneSTSymbolLocation >= 0; currentRightOneSTSymbolLocation--) {
                if (FullFilePath.charAt(currentRightOneSTSymbolLocation) === "\\" || FullFilePath.charAt(currentRightOneSTSymbolLocation) === "/") {
                    break;
                }
            }
            if (currentRightOneSTSymbolLocation === 0) {
                finalFileOnPath = FullFilePath.substr(0, 1);
            } else {
                finalFileOnPath = FullFilePath.substr(0, currentRightOneSTSymbolLocation);
            }
        } else {
            finalFileOnPath = undefined;
        }
    } else {
        finalFileOnPath = undefined;
    }
    return finalFileOnPath;
}

/**文件读写*/
import {FileDataReader, FileDataWrite} from "./DataStream";

export {
    FileDataReader,
    FileDataWrite,
    SpecialReservedCharacterDetect,
    getFullPathFileOrDirectoryName,
    getFileNameExtName,
    getFileOnDirectoryLocation
};
